<template>
  <div class="paper-upload-container">
    <el-table
      :data="awardList"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="奖项编号" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="奖项备注">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="颁奖组织">
        <template slot-scope="scope">
          <span>{{ scope.row.organizationId }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="操作" width="300" align="center">
        <template slot-scope="scope">
          <div class="flex-container">
            <el-button class="issue-btn" type="success" @click="issue(scope.$index)">
              颁发
            </el-button>
            <el-input v-model="inputList[scope.$index]"></el-input>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

  import {formatTime} from "../../utils/timeFormat";
  import {teacherIssueAward, teacherQueryAllAward} from "../../api/admin";
  import {organizationMap} from "../../constants";

  export default {
    name: "issue",
    data() {
      return {
        name: 'issue',
        labelInput: '',
        awardList: [],
        inputList: [],
      }
    },
    methods: {
      pushPaper() {

      },
      issue(index) {
        let formData = new FormData();
        formData.append("userId", this.inputList[index])
        formData.append("awardId", this.awardList[index].id)
        formData.append("awardTime", formatTime(new Date()))
        teacherIssueAward(formData).then(res => {
          console.log(res)
          this.$message.success("颁发成功")
        })
      }
    },
    mounted() {
      console.log(formatTime(new Date()))
      teacherQueryAllAward().then(res => {
        // this.awardList = res.data
        for(let i = 0; i < res.data.length; ++i) {
          res.data[i].organizationId = organizationMap[res.data[i].organizationId.toString()]
          this.inputList.push('')
          // res.data[i].index = i
        }
        this.awardList = res.data
      })
    }
  }
</script>

<style lang="scss" scoped>
  .issue-btn {
    margin-right: 5px;
    width: 60px;
    height: 40px;
    text-align: center;
    padding: 5px;
    box-sizing: border-box;
  }
  .flex-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .upload-icon {
    font-size: 24px;
    position: relative;
    top: 1px;
  }
  .paper-upload {
    &-container {
      min-height: 90vh;
      margin: 15px;
      padding: 25px;
      background-color: white;
      border-radius: 5px;
    }
    &-form-item {
      display: flex;
      align-items: center;
      font-size: 18px;
      margin-bottom: 30px;
      &-label {
        width: 95px;
      }
      &-input {
        font-size: 14px;
        width: 200px;
      }
      &-pl {
        display: flex;
        max-width: 800px;
        flex-wrap: wrap;
        align-items: center;
      }
      &-file {
        position: relative;
        top: 2px;
        margin-right: 10px;
        margin-left: 10px;
        margin-bottom: 3px;
      }
    }
  }
</style>
